package com.caiya.service.impl;

import com.caiya.cart.dto.type.CartBrandListDto;
import com.caiya.cart.entity.CartType;
import com.caiya.cart.vo.type.AddCartTypeVo;
import com.caiya.cart.vo.type.CartTypeListVo;
import com.caiya.cart.vo.type.DelTypeVo;
import com.caiya.cart.vo.type.UpdateTypeVo;
import com.caiya.mapper.CartTypeMapper;
import com.caiya.service.CartTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/11/30 0030.
 */
@Service
public class CartTypeServiceImpl implements CartTypeService{

    @Autowired
    private CartTypeMapper cartTypeMapper;

    @Override
    public PageInfo<CartBrandListDto> list(CartTypeListVo cartRequest) {
        PageHelper.startPage(cartRequest.getPageNum(),cartRequest.getPageSize());
        List<CartBrandListDto> list = cartTypeMapper.list(cartRequest);
        PageInfo<CartBrandListDto> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public int add(AddCartTypeVo addCartTypeVo) {
        CartType cartType = new CartType();
        cartType.setTypeName(addCartTypeVo.getTypeName());
        cartType.setParentId(Long.valueOf(addCartTypeVo.getParentId()));
        cartType.setSort(Integer.valueOf(addCartTypeVo.getSort()));
        int i = cartTypeMapper.insert(cartType);
        return i;
    }

    @Override
    public int update(UpdateTypeVo updateTypeVo) {
        return cartTypeMapper.update(updateTypeVo);
    }

    @Override
    public int del(DelTypeVo delTypeVo) {
        return cartTypeMapper.del(delTypeVo);
    }
}
